
package JET.SA;

import JET.SceneItem;
import JET.editor.SelectionGroup;
import JET.physics.*;
import JET.physics.bodies.SpringBody;
import java.util.Collection;

/**
 * @author 057Ry
 */
public class SA_SceneItems {

    public static SceneItem buildSceneItemFromSelectionGroup(SelectionGroup group)
    {
        SceneItem sItem = new SceneItem();

        // Inserts all selected spring bodies
        for(SpringBody sb : group.getSpringBodies())
            if (sb.getOwnerType().equals(SpringBody.OwnerType.Engine)) {
                SA_SpringBody.removeSpringBody(sb, group.getScene());
                    sItem.getEngine().addSpringBody(sb);
            }

        Collection<Spring> springCol = group.getSpringListSync();
        synchronized(springCol) {
            for(Spring s : springCol)
                if (s.getType().equals(Spring.Type.Engine)) {
                    SA_Spring.removeSpringFromEngine(s, group.getScene());
                    sItem.getEngine().addSpring(s);
                }
        }

        Collection<RSpring> rSpringCol = group.getRSpringListSync();
        synchronized(rSpringCol) {
            for(RSpring s : rSpringCol)
                if (s.getType().equals(RSpring.Type.Engine)) {
                    SA_RSpring.removeRSpringFromEngine(s, group.getScene());
                    sItem.getEngine().addRSpring(s);
                }
        }

        return sItem;
    }
}